function openurl(url, type) {
    var callback = getUrl(document.URL) + "/popup.html";
    var newUrl = url + "&state=" + type + "_" + callback;
    window.open(newUrl, "_blank", "toolbar=no, scrollbars=yes, resizable=yes, top=100, left=100, width=600, height=400");
}
function getUrl(url) {
    var index = url.lastIndexOf("/");
    return url.substring(0, index);
}